package drops.control;

import java.util.LinkedList;
import java.util.List;

import org.apache.torque.util.Criteria;

import drops.dao.Patient;
import drops.dao.PatientPeer;

public class PatientControl {
	//TODO
	
	public static int addPatient(String patientFirstName, String patientMiddleName, String patientLastName, String address, String contactNumber, int age, String occupation, String status, String complain) {
		if (validatePatient(patientFirstName, patientMiddleName, patientLastName, address, contactNumber, age, occupation, status, complain)) {
			return PatientPeer.addPatient(patientFirstName, patientMiddleName, patientLastName, address, contactNumber, age, occupation, status, complain);
		}
		return -1;
	}
	
	public static boolean editPatient(int patientNumber, String patientFirstName, String patientMiddleName, String patientLastName, String address, String contactNumber, int age, String occupation, String status, String complain) {
		if (validatePatient(patientFirstName, patientMiddleName, patientLastName, address, contactNumber, age, occupation, status, complain)) {
			return PatientPeer.editPatient(patientNumber, patientFirstName, patientMiddleName, patientLastName, address, contactNumber, age, occupation, status, complain);
		}
		return false;
	}
	
	private static boolean validatePatient(String patientFirstName, String patientMiddleName, String patientLastName, String address, String contactNumber, int age, String occupation, String status, String complain) {
		if (patientFirstName==""||patientFirstName.length()>30) return false;
		if (patientMiddleName=="") return false;
		if (patientLastName=="") return false;
		return true;
	}
	
	public static List<Patient> searchPatient(String input, String category) {
		if (category=="Patient Number") {
			List<Patient> pList = new LinkedList <Patient> ();
			Patient p;
			if ((p = searchPatientByNumber(Integer.parseInt(input)))!=null) {
				pList.add(p);
			}
			return pList;
		}
		else if (category=="Name") {
			return searchPatientByName(input);
		}
		else if (category=="Address") {
			return searchPatientByAddress(input);
		}
		return null;
	}
	
	public static List<Patient> searchPatientByAddress(String address) {
		return PatientPeer.searchPatientByAddress(address);
	}
	
	public static List<Patient> searchPatientByName(String name) {
		return PatientPeer.searchPatientByName(name);
	}
	
	public static Patient searchPatientByNumber(int patientNumber) {
		return PatientPeer.searchPatientByNumber(patientNumber);
	}
	public static void deletePatient(int patientNumber) {
		PatientPeer.deletePatient(patientNumber);
	}
}